<?php

require_once 'init.php';

if ( isset( $_GET['id'] ) )
	$id = intval( stripslashes( $_GET['id'] ) );
else
	exit;

require_once BASEDIR . 'lib/classes/sql.php';
$sql = new Sql();

require_once BASEDIR . 'lib/classes/language.php';

if ( isset( $_GET['lang'] ) )
	$uso_language = new USO_language( stripslashes( $_GET['lang'] ) );
else
	$uso_language = new USO_language();

$count = mysql_num_rows( $sql->select_strings( $id ) );

if ( 1 > $count )
	exit;

$array = mysql_fetch_array( $sql->data );

$uso_language->language_strings = unserialize( $array["strings"] );
$uso_language->default = $array["default"];
$uso_language->id = $id;

if ( isset( $_GET['fmt'] ) )
	$format = strtolower( stripslashes( $_GET['fmt'] ) );
else
	$format = "jsonp";

if ( isset( $_GET['var'] ) )
	$var = stripslashes( $_GET['var'] );
else
	$var = false;

if ( $format == "json" )
{
	header("Content-type: application/json");
	echo $uso_language->translate_to_json();
}
else if ( $format == "xml" )
{
	header("Content-type: text/xml");
	echo $uso_language->translate_to_xml()->saveXML();
}
else
{
	header("Content-type: application/x-javascript");
	if ( $var )
		echo "var " . $var . " = (" . $uso_language->translate_to_json() . ");";
	else { ?>if ( typeof USO !== 'object' )
  var USO = {};
USO.translate = (<?=$uso_language->translate_to_json()?>);<?php }
}

?>